﻿using Microsoft.EntityFrameworkCore.Migrations;
using System;

namespace AbpCompanyName.AbpProjectName.Migrations;

public partial class Upgraded_To_Abp_5_2_0 : Migration
{
    protected override void Up(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.CreateTable(
            name: "AbpWebhookEvents",
            columns: table => new
            {
                Id = table.Column<Guid>(nullable: false),
                WebhookName = table.Column<string>(nullable: false),
                Data = table.Column<string>(nullable: true),
                CreationTime = table.Column<DateTime>(nullable: false),
                TenantId = table.Column<int>(nullable: true),
                IsDeleted = table.Column<bool>(nullable: false),
                DeletionTime = table.Column<DateTime>(nullable: true)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_AbpWebhookEvents", x => x.Id);
            });

        migrationBuilder.CreateTable(
            name: "AbpWebhookSubscriptions",
            columns: table => new
            {
                Id = table.Column<Guid>(nullable: false),
                CreationTime = table.Column<DateTime>(nullable: false),
                CreatorUserId = table.Column<long>(nullable: true),
                TenantId = table.Column<int>(nullable: true),
                WebhookUri = table.Column<string>(nullable: false),
                Secret = table.Column<string>(nullable: false),
                IsActive = table.Column<bool>(nullable: false),
                Webhooks = table.Column<string>(nullable: true),
                Headers = table.Column<string>(nullable: true)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_AbpWebhookSubscriptions", x => x.Id);
            });

        migrationBuilder.CreateTable(
            name: "AbpWebhookSendAttempts",
            columns: table => new
            {
                Id = table.Column<Guid>(nullable: false),
                WebhookEventId = table.Column<Guid>(nullable: false),
                WebhookSubscriptionId = table.Column<Guid>(nullable: false),
                Response = table.Column<string>(nullable: true),
                ResponseStatusCode = table.Column<int>(nullable: true),
                CreationTime = table.Column<DateTime>(nullable: false),
                LastModificationTime = table.Column<DateTime>(nullable: true),
                TenantId = table.Column<int>(nullable: true)
            },
            constraints: table =>
            {
                table.PrimaryKey("PK_AbpWebhookSendAttempts", x => x.Id);
                table.ForeignKey(
                    name: "FK_AbpWebhookSendAttempts_AbpWebhookEvents_WebhookEventId",
                    column: x => x.WebhookEventId,
                    principalTable: "AbpWebhookEvents",
                    principalColumn: "Id",
                    onDelete: ReferentialAction.Cascade);
            });

        migrationBuilder.CreateIndex(
            name: "IX_AbpWebhookSendAttempts_WebhookEventId",
            table: "AbpWebhookSendAttempts",
            column: "WebhookEventId");
    }

    protected override void Down(MigrationBuilder migrationBuilder)
    {
        migrationBuilder.DropTable(
            name: "AbpWebhookSendAttempts");

        migrationBuilder.DropTable(
            name: "AbpWebhookSubscriptions");

        migrationBuilder.DropTable(
            name: "AbpWebhookEvents");
    }
}
